#!/bin/sh -e
#
# This script is automatically invoked after each successful transaction.
# It runs @RPMCONFIGDIR@/*.filetrigger programs, with full list of filenames
# affected by the transaction attached to stdin.  In *.filetrigger programs,
# explicit file tests can be used, e.g. [ -f file ], to determine if particular
# files were installed/updated or removed.
#
# Copyright (C) 2008  Alexey Tourbin <at@altlinux.org>
#
# Loosely based on filetriggers.patch from Mandriva Linux.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# Passed by rpm (usually /var/lib/rpm/files-awaiting-filetriggers).
filelist="${1:?}"
shift

RC=0

if [ -s "$filelist" ]; then
	LC_ALL=C sort -u -o "$filelist" "$filelist"
	for filetrigger in @RPMCONFIGDIR@/*.filetrigger; do
		if ! [ -x "$filetrigger" ]; then
			continue
		fi
		if ! "$filetrigger" <"$filelist"; then
			echo >&2 "$filetrigger failed"
			RC=1
		fi
	done
fi

exit $RC
